"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const redux_1 = require("@tarojs/redux");
const taro_1 = require("@tarojs/taro");
const components_1 = require("@tarojs/components");
const taro_ui_1 = require("taro-ui");
const apply_1 = require("../../../actions/apply");
require("./index.scss");
let Apply = class Apply extends taro_1.Component {
    constructor() {
        super(...arguments);
        this.config = {
            navigationBarTitleText: '我要上首页'
        };
        this.state = {
            data: {
                name: '',
                company: '',
                phone: '',
                brief: '',
            },
            isToastOpened: false,
            toastTips: ''
        };
        this.handleChange = (key, value) => {
            this.setState(state => (Object.assign({}, state, { data: Object.assign({}, state.data, { [key]: key === 'brief' ? value.target.value : value }) })), () => {
                console.log(this.state.data[key], key, value);
            });
        };
        this.onSubmit = () => {
            taro_1.default.getSetting().then(e => {
                if (e.authSetting['scope.userInfo']) {
                    // 上首页申请
                    const values = this.state.data;
                    let flag = true;
                    Object.keys(values).forEach(item => {
                        if (String(values[item]).trim() === '') {
                            flag = false;
                            this.setState(state => (Object.assign({}, state, { isToastOpened: true, toastTips: `${item} 不能为空！` })));
                        }
                    });
                    if (flag)
                        this.props.add(values, () => {
                            taro_1.default.showToast({ title: '上首页申请提交成功~', icon: 'none' });
                        });
                }
                else {
                    taro_1.default.showToast({ title: '请先登录！', icon: 'none' });
                }
            });
        };
    }
    componentWillMount() {
    }
    render() {
        return (<components_1.View>
				<taro_ui_1.AtToast isOpened={this.state.isToastOpened} text={this.state.toastTips}/>
				<taro_ui_1.AtNoticebar>首页抽奖为合作推广内容，如需上首页请填写下列信息</taro_ui_1.AtNoticebar>
				<taro_ui_1.AtForm onSubmit={this.onSubmit.bind(this)}>
					<taro_ui_1.AtInput name='name' title='个人姓名' type='text' placeholder='请输入姓名' value={this.state.name} onChange={this.handleChange.bind(this, 'name')}/>
					<taro_ui_1.AtInput name='company' title='公司名称' type='text' placeholder='请输入公司名称' value={this.state.company} onChange={this.handleChange.bind(this, 'company')}/>
					<taro_ui_1.AtInput name='phone' border={false} title='联系电话' type='phone' placeholder='请输入联系电话' value={this.state.phone} onChange={this.handleChange.bind(this, 'phone')}/>
					<components_1.View className='intro'>
						<components_1.View className='title'>
							<components_1.Text className='text'>推广简介</components_1.Text>
						</components_1.View>
						<taro_ui_1.AtTextarea value={this.state.brief} onChange={this.handleChange.bind(this, 'brief')} maxlength='200' placeholder='请输入期望推广的内容简述...' className='content'/>
					</components_1.View>
					<components_1.View className='btn-group'>
						<taro_ui_1.AtButton type='primary' formType='submit'>提交</taro_ui_1.AtButton>
					</components_1.View>
				</taro_ui_1.AtForm>
			</components_1.View>);
    }
};
Apply = __decorate([
    redux_1.connect(({ apply }) => ({
        apply
    }), (dispatch) => ({
        add(data, callback) {
            dispatch(apply_1.add(data, callback));
        }
    }))
], Apply);
exports.default = Apply;
//# sourceMappingURL=index.jsx.map